var e = require("../../../@babel/runtime/helpers/typeof"), t = getApp();

Page({
    data: {
        language: "",
        selected: 0,
        selectedidx: "1",
        page: 1,
        pageSize: 10,
        total_page: 0,
        isPresenter: !1,
        wait_used: [],
        overdue: [],
        used: [],
        usermessage: {
            value: "",
            item: "",
            index: ""
        },
        presentershow: !1,
        display: 99999,
        listData: [ {
            type: 1
        }, {
            type: 2
        }, {
            type: 3
        }, {
            type: 4
        }, {
            type: 5
        }, {
            type: 6
        }, {
            type: 7
        } ],
        bottomIndex: "",
        types: [],
        typesIndex: 0,
        kFootshow: !0,
        write_off_coupon: !1,
        share_coupon: !1,
        combine_show: !1,
        couponListDataSet: [],
        couponListData: [],
        colors: [ "#fbbd5c", "#ff8383", "#a291ff", "#f095ed", "#6dccf8", "#fb946c", "#cecece" ]
    },
    onLoad: function(e) {},
    tapGo: function(e) {
        if ("1" == this.data.selectedidx) {
            var t = e.currentTarget.dataset.info;
            this.data.isPresenter && (t.isPresenter = this.data.isPresenter), t.num, wx.navigateTo({
                url: "/packageA/member/coupon_v2_detail/coupon_v2_detail?id=".concat(t.id, "&combine=").concat(t.combine, "&combine_show=").concat(this.data.combine_show)
            });
        }
    },
    showButton: function(e) {
        var t = e.detail;
        console.log(e.detail), 1 == this.data.selectedidx ? (this.data.wait_used[t].openIs = !this.data.wait_used[t].openIs, 
        this.setData({
            wait_used: this.data.wait_used
        })) : 2 == this.data.selectedidx ? (this.data.overdue[t].openIs = !this.data.overdue[t].openIs, 
        this.setData({
            overdue: this.data.overdue
        })) : 3 == this.data.selectedidx && (this.data.used[t].openIs = !this.data.used[t].openIs, 
        this.setData({
            used: this.data.used
        }));
    },
    setTypesIndex: function(e) {
        var t = e.currentTarget.dataset.index;
        t != this.data.typesIndex && (this.setData({
            typesIndex: t
        }), this._getNetData(this.data.selectedidx, t));
    },
    onReady: function() {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {
        this._initData(), this._getNetData(1, this.data.typesIndex);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        var e = this.data.page, t = this.data.pageSize, a = e * t, o = (e + 1) * t;
        if (console.log(a, o), !(a >= this.data.couponListDataSet.length)) {
            o > this.data.couponListDataSet.length && (o = this.data.couponListDataSet.length);
            var s = this.data.couponListDataSet.slice(a, o);
            this.setData({
                page: e + 1,
                couponListData: this.data.couponListData.concat(s)
            }), console.log(this.data.page);
        }
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {},
    getmemberInfo: function(e) {
        var a = e.detail.value, o = this, s = t.getNetAddresss("member.member.memberInfo");
        s += "&uid=" + a, t._getNetWork({
            url: s,
            success: function(e) {
                var t = e.data;
                1 == t.result && o.setData({
                    memberInfo: t.data.nickname ? t.data.nickname : ""
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _getNetData: function(a, o) {
        var s = this;
        wx.tempCqSwipeCell && wx.tempCqSwipeCell.setData({
            prevBox: 0
        }), this.setData({
            couponListData: []
        });
        var n = this;
        this.data.page = 1;
        var i = t.getNetAddresss("coupon.member-coupon.coupons-of-member-by-status-v2");
        1 == t.globalData.store_alone_temp && (i = t.getNetAddresss("plugin.store-alone-temp.frontend.coupon.coupons-of-member-by-status-v2")), 
        i += "&status_request=" + a, i += "&coupon_type=" + o, i += "&page=1", t._getNetWork({
            url: i,
            success: function(a) {
                var o = a.data;
                if (1 == o.result) {
                    var i = o.data;
                    if (n.data.total_page = o.data.total ? o.data.total : 0, n.data.couponListDataSet = i.data, 
                    console.log(e(o.data.search_array)), o.data.set && n.setData({
                        isPresenter: o.data.set.transfer
                    }), o.data.search_array) {
                        n.setData({
                            types: o.data.search_array || []
                        });
                        for (var r = 0; r < i.data.length; r++) i.data[r].openIs = !1, i.data[r].ind = r, 
                        "门店商品" == i.data[r].belongs_to_coupon.coupon_type_name ? i.data[r].type = 6 : "平台商品" == i.data[r].belongs_to_coupon.coupon_type_name ? i.data[r].type = 1 : "兑换券" == i.data[r].belongs_to_coupon.coupon_type_name ? i.data[r].type = 2 : "分类商品" == i.data[r].belongs_to_coupon.coupon_type_name ? i.data[r].type = 3 : "指定商品" == i.data[r].belongs_to_coupon.coupon_type_name ? i.data[r].type = 4 : "酒店商品" == i.data[r].belongs_to_coupon.coupon_type_name ? i.data[r].type = 5 : "商品和门店" == i.data[r].belongs_to_coupon.coupon_type_name && (i.data[r].type = 8);
                    }
                    n.setData({
                        couponListData: n.data.couponListDataSet.slice(0, n.data.pageSize),
                        combine_show: o.data.combine_show
                    }), t._isTextEmpty(i.share_coupon) || s.setData({
                        share_coupon: i.share_coupon
                    });
                } else wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    switchItem: function(e) {
        var t = e.detail.index;
        t + 1 != this.data.selectedidx && (0 == t ? this.setData({
            selectedidx: "1"
        }) : 1 == t ? this.setData({
            selectedidx: "2"
        }) : 2 == t && this.setData({
            selectedidx: "3"
        }), this._initData(), console.log(this.data.typesIndex), this._getNetData(this.data.selectedidx, this.data.typesIndex));
    },
    _initData: function() {
        this.setData({
            page: 1,
            goload: !0,
            total_page: 0,
            allLoaded: !1,
            isLoadMore: !0,
            isPresenter: !1
        });
    },
    presenterOnce: function(e) {
        console.log(e);
        var t = e.detail.item, a = e.detail.ind;
        this.presenter(t, a);
    },
    presenter: function(e, t) {
        this.setData({
            "usermessage.value": "",
            "usermessage.item": "",
            "usermessage.index": "",
            memberInfo: ""
        }), this.setData({
            "usermessage.item": e,
            "usermessage.index": t,
            presentershow: !0
        });
    },
    onconfirm: function(e) {
        if (t._isTextEmpty(this.data.usermessage.value)) return wx.showToast({
            icon: "none",
            title: "用户ID不能为空",
            duration: 1e3
        }), void this.setData({
            presentershow: !1
        });
        this._presenterPost(this.data.usermessage.value, this.data.usermessage.item, this.data.usermessage.index);
    },
    onclose: function(e) {
        this.setData({
            "usermessage.value": "",
            "usermessage.item": "",
            "usermessage.index": ""
        }), this.setData({
            presentershow: !1
        });
    },
    usermesbut: function(e) {
        var t = e.detail.value;
        this.setData({
            "usermessage.value": t
        });
    },
    _presenterPost: function(e, a, o) {
        var s = this, n = t.getNetAddresss("coupon.coupon-transfer.index");
        n += "&recipient=" + e, n += "&record_id=" + a.id, t._getNetWork({
            url: n,
            success: function(e) {
                var t = e.data;
                if (1 == t.result) {
                    if (s.data.wait_used.length > 0) {
                        var a = s.data.wait_used;
                        a.splice(o, 1), s.setData({
                            wait_used: a
                        }), wx.showToast({
                            icon: "none",
                            title: "操作成功",
                            duration: 1500
                        });
                    }
                    s.setData({
                        presentershow: !1
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                }), s.setData({
                    presentershow: !1
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    goBuyOnce: function(e) {
        console.log(e);
        var t = e.detail.item, a = e.detail.ind;
        this.goBuy(t, a);
    },
    goBuy: function(e, t) {
        console.log("packageB/member/category/search_v2/search_v2"), 0 == e.belongs_to_coupon.use_type ? this.goHome() : 1 == e.belongs_to_coupon.use_type ? wx.navigateTo({
            url: "/packageB/member/category/catelist/catelist?id=" + JSON.stringify(e.belongs_to_coupon.category_ids) + "&fromHome=1"
        }) : 2 == e.belongs_to_coupon.use_type ? wx.navigateTo({
            url: "/packageB/member/category/search_v2/search_v2?coupon=" + e.belongs_to_coupon.id + "&fromHome=1"
        }) : 4 === e.belongs_to_coupon.use_type && Array.isArray(e.belongs_to_coupon.storeids) ? wx.navigateTo({
            url: "/packageC/o2o/o2oHome/o2oHome"
        }) : 5 === e.belongs_to_coupon.use_type && "number" == typeof e.belongs_to_coupon.storeids ? wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + e.belongs_to_coupon.storeids
        }) : 7 === e.belongs_to_coupon.use_type && Array.isArray(e.belongs_to_coupon.hotel_ids) ? wx.navigateTo({
            url: "/packageC/hotel/HotelIndex/HotelIndex"
        }) : 6 === e.belongs_to_coupon.use_type && "number" == typeof e.belongs_to_coupon.hotel_ids ? wx.navigateTo({
            url: "/packageC/hotel/HotelHome/HotelHome?id=" + e.belongs_to_coupon.hotel_ids
        }) : 8 === e.belongs_to_coupon.use_type ? wx.navigateTo({
            url: "/packageB/member/category/search_v2/search_v2?keyword=" + e.belongs_to_coupon.goods_ids[0]
        }) : this.goHome();
    },
    goHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    toggle: function(e) {
        var t = e.currentTarget.dataset.index;
        this.data.display == t ? this.setData({
            display: 99999
        }) : this.setData({
            display: t
        });
    },
    delteteItem: function(e) {
        var a = this;
        console.log(e);
        var o = e.currentTarget.dataset.item, s = e.currentTarget.dataset.index, n = t.getNetAddresss("coupon.member-coupon.delete");
        n += "&id=" + o.id, wx.tempCqSwipeCell && wx.tempCqSwipeCell.setData({
            prevBox: 0
        }), t._getNetWork({
            url: n,
            success: function(e) {
                var t = e.data;
                if (1 == t.result) {
                    var o = a.data.couponListData;
                    o.splice(s, 1), a.setData({
                        couponListData: o
                    }), wx.showToast({
                        icon: "none",
                        title: "操作成功",
                        duration: 1e3
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    gocouponStore: function() {
        wx.redirectTo({
            url: "/packageD/coupon/coupon_store"
        });
    },
    usermesbutInput: function(e) {
        var t = e.detail.value;
        this.data.usermessage.value = t;
    },
    tabrshowbtn: function(e) {
        e.detail && this.setData({
            kFootshow: !1
        });
    }
});